<template>
  <section>

    <el-table :data="ConfData" highlight-current-row v-loading="listLoading" style="width: 100%;">
      <el-table-column type="selection" width="55">
      </el-table-column>
      <el-table-column type="index" label='序号' min-width="60">
      </el-table-column>
      <el-table-column prop="title" label="已绑定参数名称" min-width="200" sortable>
      </el-table-column>
      <el-table-column prop="max" label="上限阈值" min-width="200" sortable>
      </el-table-column>
      <el-table-column prop="min" label="下限阈值" min-width="200" sortable>
      </el-table-column>
      <el-table-column prop="b" label="倍数" min-width="100" sortable>
      </el-table-column>

      <el-table-column label="操作" width="250">
        <template slot-scope="scope">
          <el-button size="small" @click="handleEdit(scope.$index, scope.row)">设置阈值</el-button>
        </template>
      </el-table-column>
    </el-table>


    <el-dialog title="参数预警设置" :visible.sync="editFormVisible" :close-on-click-modal="false">
      <el-form :model="editForm" label-width="80px" :rules="editFormRules" ref="editForm">
        <el-form-item label="参数名称" prop="title">
          <el-input v-model="editForm.title" auto-complete="off" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="最大值">
          <el-input v-model="editForm.max" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="最小值">
          <el-input v-model="editForm.min" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="倍数">
          <el-input v-model="editForm.b" auto-complete="off"></el-input>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="editFormVisible = false">取消</el-button>
        <el-button type="success" @click.native="editSubmit" :loading="editLoading">提交</el-button>
      </div>
    </el-dialog>

  </section>
</template>

<script>
  export default {
    created() {},
    mounted() {
      this.device_id = this.$route.query.device_id;
      this.getDeviceConfs();
    },
    data() {
      return {
        device_id: '',
        ConfData: [],
        unBandConfData: [],
        // max: '',
        // min: '',
        // b:'',

        listLoading: false,
        editFormVisible: false, //编辑界面是否显示
        editLoading: false,
        editFormRules: {
          title: [{
            required: true,
            message: '',
            trigger: 'blur'
          }]
        },
        //编辑界面数据
        editForm: {


        },

      }
    },
    methods: {
      getDeviceConfs() {

        var params = {
          device_id: this.device_id,
        }
        this.api.get('/work/awbDevice/confListWithDeviceId', {params: params}).then((res) => {
          this.ConfData = res.data.result;
        });
      },
      //显示编辑界面
      handleEdit: function(index, row) {
        this.editFormVisible = true;
        this.editForm = Object.assign({}, row);
        // this.editForm.set()
      },
      //编辑
      editSubmit: function() {
        this.$refs.editForm.validate((valid) => {
          if (valid) {
            this.$confirm('确认提交吗？', '提示', {}).then(() => {
              // this.editLoading = true;
              if (this.editForm.max == null){

                this.editForm.max = '';
              }
              if (this.editForm.min == null ){

                this.editForm.min = '';
              }
              if (this.editForm.b == null ){

                this.editForm.b = '';
              }
              let params = {

                conf_id: this.editForm.confId,
                device_id: this.device_id,
                max: this.editForm.max,
                min: this.editForm.min,
                b:this.editForm.b
              }
              console.log(params);
              this.api.post('/work/awbDevice/updateDeviceWarn', params).then((res) => {
                if(res){
                  this.editFormVisible = false;
                  this.$message.success('操作成功');
                  this.getDeviceConfs();
                }
                this.editLoading = false;
              });

            });
          }
        });
      }
    }
  }
</script>

<style>
</style>
